<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:73:"D:\laragon\www\zgh\public/../application/admin\view\admin\admin_edit.html";i:1531297544;}*/ ?>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>知果汇</title>
    <link href="_CSS_/bootstrap.min.css" rel="stylesheet">
    <link href="_CSS_/simple-line-icons.css" rel="stylesheet">
    <link href="_CSS_/font-awesome.min.css" rel="stylesheet">
    <link href="_CSS_/jasny-bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="_CSS_/nanoscroller.css">
    <link href="_CSS_/style.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="_CSS_/jquery-ui.css">
    <!--[if lt IE 9]>
    <script src="_JS_/html5shiv.min.js"></script>
    <script src="_JS_/respond.min.js"></script>
    <![endif]-->
    <style type="text/css">
        body {
            background-color: #ffffff;
        }

        .row {
            margin-left: 0px;
            margin-right: 0px;
        }

        .radio-box {
            display: inline-block;
            width: 64px;
        }

        .formControls {
            padding-right: 50px;
            position: relative;
        }

        .textarea {
            height: 100px;
            resize: none;
            font-size: 14px;
            padding: 4px;
        }

        .textarea-numberbar {
            position: absolute;
            right: 70px;
            bottom: 5px;
            z-index: 1;
            margin-bottom: 0;
        }
    </style>
</head>
<body>
<article class="page-container">
    <form class="form form-horizontal" id="form-admin-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理员：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="adminName" name="adminName">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>性别：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                <div class="radio-box">
                    <input name="sex" type="radio" id="sex-1" checked>
                    <label for="sex-1">男</label>
                </div>
                <div class="radio-box">
                    <input type="radio" id="sex-2" name="sex">
                    <label for="sex-2">女</label>
                </div>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>手机：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="phone" name="phone">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>邮箱：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="@" name="email" id="email">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">角色：</label>
            <div class="formControls col-xs-8 col-sm-9"> <span class="select-box" style="width:150px;">
					<select class="select" name="adminRole" id="adminRole" size="1">
						
					</select>
					</span></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">备注：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea name="" cols="" rows="" id="desc" class="textarea" placeholder="说点什么...100个字符以内"
                          dragonfly="true" onKeyUp="textarealength(this,100)"></textarea>
                <p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>新密码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="password" class="input-text" value="" placeholder="" id="password" name="password">
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                <input class="btn btn-cancel radius" style="color: #ffffff;background-color: #a0a0a0;" type="button"
                       value="&nbsp;&nbsp;取消&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

<script src="_JS_/jquery.min.js"></script>
<script src="_JS_/bootstrap.min.js"></script>
<script src="_JS_/jasny-bootstrap.min.js"></script>
<script src="_JS_/jquery.slimscroll.min.js"></script>
<script src="_JS_/jquery.nanoscroller.min.js"></script>
<script src="_JS_/metismenu.min.js"></script>
<script src="_JS_/float-custom.js"></script>
<script type="text/javascript" src="_JS_/layer/layer.js"></script>
<script type="text/javascript" src="_JS_/jquery.validation/1.14.0/jquery.validate.min.js"></script>
<script type="text/javascript" src="_JS_/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="_JS_/jquery.validation/1.14.0/messages_zh.min.js"></script>

<script type="text/javascript">
    var url = window.location.href;
    uid = url.split("#")[1];
    //uid=17;
    /*textarea 字数限制*/
    function textarealength(obj, maxlength) {
        var v = $(obj).val();
        var l = v.length;
        if (l > maxlength) {
            v = v.substring(0, maxlength);
            $(obj).val(v);
        }
        $(obj).parent().find(".textarea-length").text(v.length);
    }

    $(function () {
        //获取角色列表
        $.ajax({
            type: "get",
            url: "<?php echo url('api/admin/auth_role'); ?>",
            dataType: 'jsonp',
            jsonp: 'callback',
            success: function (msg) {
                if (msg.code == 200) {
                    for (var i = 0; i < msg.data.length; i++) {
                        var html = '<option value="' + msg.data[i].id + '">' + msg.data[i].name + '</option>';
                        $("#adminRole").append(html);
                    }
                }
                if (msg.code == 1000) {
                    layer.msg('删除失败!', {icon: 1, time: 1000});
                }
            }
        });

        //获取用户信息
        $.ajax({
            type: "get",
            url: "<?php echo url('api/admin/admin_edit'); ?>",
            dataType: 'jsonp',
            jsonp: 'callback',
            data: {'uid': uid},
            success: function (msg) {
                if (msg.code == 200) {
                    $("#adminName").val(msg.data.username);
                    $("input[name='sex']").val(msg.data.sex);
                    $("#phone").val(msg.data.phone);
                    $("#email").val(msg.data.email);
                    $("#adminRole").val(msg.data.r_id);
                    $("#desc").val(msg.data.describe);
                }
                if (msg.code == 1000) {
                    layer.msg(msg.message, {icon: 1, time: 1000});
                }
            }
        })

        $("#form-admin-add").validate({
            rules: {
                adminName: {
                    required: true,
                    minlength: 4,
                    maxlength: 16
                },
                sex: {
                    required: true,
                },
                adminRole: {
                    required: true,
                },
            },
            onkeyup: false,
            focusCleanup: true,
            success: "valid",
            submitHandler: function (form) {
                var username = $("#adminName").val();
                password = $("#password").val();
                sex = $("input[name='sex']:checked").val();
                phone = $("#phone").val();
                email = $("#email").val();
                r_id = $("#adminRole").val();
                desc = $("#desc").val();

                $.ajax({
                    type: "get",
                    url: "<?php echo url('api/admin/revise_info'); ?>",
                    dataType: 'jsonp',
                    jsonp: 'callback',
                    data: {
                        'uid': uid,
                        'username': username,
                        'sex': sex,
                        'password': password,
                        'phone': phone,
                        'email': email,
                        'r_id': r_id,
                        'desc': desc
                    },
                    success: function (msg) {
                        if (msg.code == 200) {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            parent.getlist(1);
                        }
                        if (msg.code == 1000) {
                            layer.msg(msg.message, {icon: 1, time: 1000});
                        }
                    }
                });
            }
        });
    });
</script>
</body>
</html>